package com.example.messagequeue.demo;

import com.example.messagequeue.mqclient.Channel;
import com.example.messagequeue.mqclient.Connection;
import com.example.messagequeue.mqclient.ConnectionFactory;
import com.example.messagequeue.mqserver.core.ExchangeType;

import java.io.IOException;

public class DemoProducer {
    public static void main(String[] args) throws IOException, InterruptedException {
        System.out.println("[启动生产者]");
        ConnectionFactory factory = new ConnectionFactory();
        factory.setPort(9090);
        factory.setHost("127.0.0.1");
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();

        channel.exchangeDeclare("testExchange", ExchangeType.DIRECT, true, false, null);
        channel.queueDeclare("testQueue", true, false, false, null);

        byte[] body = "hello".getBytes();
        boolean ok = channel.basicPublish("testExchange", "testQueue", null, body);
        System.out.println("消息投递完成！ok = " + ok);
        Thread.sleep(500);
        channel.close();
        connection.close();
    }
}
